

using System;
using System.Web.Security;
using System.Collections.Generic;

using Grr;
using Grr.Models;

using Castle.MonoRail.Framework;


namespace Grr.Controllers {

	[Rescue("generalerror")]
	public class FeedController : SmartDispatcherController {
		public void Person (TaintedString id)
		{
			CancelLayout();
			Response.ContentType = "application/xml";

			if (id != null && !id.IsEmpty)
			{
				string p = StringUtil.ToDb (id.Clean());
				PropertyBag["Person"] = p;

				// We need to go through the membership API instead of joining
				// the user table, because the read connection does not have 
				// permission to look at the users table

				MembershipUser user = Membership.GetUser(p);
				if (user == null)
				{
					RenderView("no_such_person");
					return;
				}

				SearchResult created;
				SearchResult doing;
				SearchResult want_to_do;

				Grr.Models.People.GetResultsForPerson((long)user.ProviderUserKey, 10, out created, out doing, out want_to_do);

				PropertyBag["Created"] = created;
				PropertyBag["Doing"] = doing;
				PropertyBag["WantToDo"] = want_to_do;
			}
		}

		public void Feature(TaintedString friendly_name)
		{
			Feature feature = null;
			if (friendly_name != null && !friendly_name.IsEmpty)
			{
				string name = StringUtil.ToDb(friendly_name.Clean());
				feature = Grr.Models.Feature.QueryForByName(name);
			}

			if (feature == null)
				feature = Grr.Models.Feature.GetCurrentFeature();

			PropertyBag["feature"] = feature;
		}
	}
}

